﻿Imports System.Data.OleDb


Public Class Addnewdeal
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(fup_DImage.filename)
        If fup_DImage.HasFile Then
            fup_DImage.SaveAs(Server.MapPath("Dealpictures") & "/" & newFileName)
        End If



        Dim sql As String = "INSERT INTO DealDetail (Dealname,Deallink,Dealprice,Thumbnail,DealDescription,UploadedBy) VALUES (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("DealsDbConnection").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_Dname.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Durl.Text)
        cmd.Parameters.AddWithValue("@f3", tb_Dprice.Text)
        cmd.Parameters.AddWithValue("@f4", "Dealpictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", tb_Ddescription.Text)
        cmd.Parameters.AddWithValue("@f6", User.Identity.Name)



        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("list.aspx")
    End Sub

    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class